<?php
/**
 * 描述
 * Created by Paco
 * Date: 2019/1/29 Time: 17:43
 */

namespace App\Http\Controllers\Shop;


use App\Http\Controllers\Controller;
use App\Http\Request\Shop\ProductStore;
use App\Repositories\Shop\ProductRepository;
use Illuminate\Http\Request;

class ProductController extends Controller
{

    private $product;

    public function __construct(ProductRepository $product)
    {
        $this->product = $product;
    }


    public function index(Request $request)
    {
        $params = $request->all();
        return $this->product->index($params);
    }

    public function show($product_id)
    {
        return $this->product->show($product_id);
    }

    /**
     *
     * store
     * author Paco
     * createTime 2019/2/15 17:10
     * @param ProductStore $product
     * @param Request $request
     * @return bool
     * @throws \Illuminate\Validation\ValidationException
     */
    public function store(ProductStore $product, Request $request)
    {
        $data = $product->validated($request);
        return $this->product->store($data);
    }


    /**
     *
     * update
     * author Paco
     * createTime 2019/2/15 17:11
     * @param ProductStore $product
     * @param Request $request
     * @return bool
     * @throws \Illuminate\Validation\ValidationException
     */
    public function update(ProductStore $product, Request $request)
    {
        $data = $product->validated($request);
        return $this->product->savePro($data);
    }

    public function shelves(Request $request)
    {
        $pro_ids = $request->input('product_ids', 0);
        $shelves = $request->input('shelves', 0);
        return $this->product->shelves($pro_ids,$shelves);
    }


    public function del(Request $request)
    {
        $pro_ids = $request->input('product_ids', 0);
        return $this->product->delProduct($pro_ids);
    }

    public function delsku(Request $request)
    {
        $sku_id = $request->input('sku_id', 0);
        return $this->product->delSku($sku_id);
    }

}